﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using NSpotifyLib.Interfaces;

namespace NSpotifyLib
{
    internal class SpotifyHTTPReader : ISpotifyHTTPReader
    {
        private const string spotifyBase = "http://ws.spotify.com/";
   
        public XDocument GetSpotifyData(string searchCriteria)
        {
            WebRequest request = WebRequest.Create(spotifyBase + searchCriteria);
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                  throw new HttpListenerException((int)response.StatusCode, "Spotify Metadata API not available");      

                return XDocument.Load(response.GetResponseStream());
            }
        }
    }
}
